<?php
// 本类由系统自动生成，仅供测试用途
class PeisongAction extends Action {

  
  //预设  para一般自身的所有以及扩展的zabojingua东西
  //聚合
    private $all=array(
      'mdmk'=>'Ps',//NB
      'ttl'=>'配送',
      'jn'=>array('tb_plan ON f_ps_planid=planid','tb_line ON f_ps_lineid=lineid','tb_item ON f_ps_itemid=itemid','tb_part ON f_ps_partid=partid','tb_psstat ON f_ps_psstatid=psstatid'),//NB
      //自己的全部+f的显示的东西
      'para'=>array('psid'=>'psID','f_ps_planid'=>'计划ID','f_ps_lineid'=>'产线','linenm'=>'产线','f_ps_itemid'=>'项目','itemnm'=>'项目名称','itemcode'=>'项目代码','f_ps_partid'=>'部件','partnm'=>'部件名称','partcode'=>'部件编号','psvolume'=>'计划总量','psalready'=>'已配送量','psremain'=>'剩余用量','psleavetm'=>'倒计时','f_ps_psstatid'=>'状态','psstatnm'=>'状态','psodr'=>'固定顺序','psclick'=>'是否点击完成'),//NB
      //抛去不是zabojin的属性针对para
      'notself'=>array('linenm','itemnm','itemcode','partnm','partcode','psstatnm'),
       ##########modify 添加修改中不需要展示和理会的属性 针对para
      'no_update'=>array('psid','linenm','itemnm','itemcode','partnm','partcode','psstatnm'),
      #####update的时候允许为空的值 针对zabojin刨掉不然显示的update字段后
      'allowempty'=>array(),

      'hide_fld'=>array('psid','f_ps_planid','f_ps_lineid','f_ps_itemid','f_ps_partid','f_ps_psstatid','plano','parto','psodr','psclick'),//NB
      'hide_cdt'=>array('psid','linenm','itemcode','partnm','partcode','psstatnm'),//NB
      
    //   'spccdtls'=>array('spccdt_0'=>array('psid<>0','psID不为0【废话只是测试】')),
      // 'odrls'=>array('psnm'),
    //   'spccdt_dflt'=>array('spccdt_0'),
    //   'odr_dflt'=>array('psnm'=>'ASC'),

      'spccdtls'=>array(),//NB
      'odrls'=>array('psodr','psleavetm'),//NB
      'spccdt_dflt'=>array(),//NB
      'odr_dflt'=>array('psodr'=>'ASC','psleavetm'=>'ASC'),//NB
      //hide的fld必须有，他们虽然不显示但是必须选择，这样才能在第一次进入query的时候，隐藏属性可以被调用，特别是id和fid
      'fld_dflt'=>array('psid','f_ps_planid','f_ps_lineid','linenm','f_ps_itemid','f_ps_partid','partnm','partcode','psvolume','psalready','psremain','psleavetm','f_ps_psstatid','psstatnm','psodr','psclick'),//NB
      'cdt_dflt'=>array(),//NB
      
      'lmt_dflt'=>10,//NB
      
      'defaultls'=>1,//默认枚举//NB
      ##########view
      'no_view'=>array('psid','f_ps_planid','f_ps_lineid','f_ps_itemid','f_ps_partid','f_ps_psstatid'),
     
      #########删除提醒
      'deleteconfirm'=>'确定要删除此条记录？',
      #####转义
      'transmean'=>array(),//NB
      #####默认值
      'dfltvalue'=>array(),
      ########新增属性
      'linkage'=>array(),//如果partc的变换需要转换成2015_partc 就是2  否则如果是1 非2情况下联动没有值，不允许下拉，3联动不造成下拉有无
      ########这里是谁影响谁，用在AJAX联动 效果极佳
      'impactfactor'=>array(),
      
    );

    //公版
    public function query(){
      header("Content-Type:text/html; charset=utf-8");
      
      $environment=D('Environment');$plan=D('Plan');$ps=D('Ps');$banci=D('Banci');$fenzuparttype=D('Fenzuparttype');$line=D('Line');$yuzhi=D('Yuzhi');
      $arr_usross=$environment->setenvironment(MODULE_NAME);$usross=$arr_usross['data'];

      $this->assign('usross',$usross);
      $arr_bancio=$banci->getbanciobybanciid($usross['f_usr_banciid']);$bancio=$arr_bancio['data'];
      $this->assign('bancio',$bancio);
      $arr_parttypels=$fenzuparttype->getparttypelsbyfenzuid($usross['f_usr_fenzuid']);$parttypels=$arr_parttypels['data'];
      $str=$parttypels[0]['parttypenm'];
      if(count($parttypels)>1){
        foreach($parttypels as $ptv){
          $str=$str.'、'.$ptv['parttypenm'];
        }
      }
      $this->assign('parttypenmset',$str);


      $arr_linels=$line->getlinels();$linels=$arr_linels['data'];
      
      // $linelsnw=array();
      // foreach($linels as $lv){
      //   $arr_psls=$ps->getpslsbylineid($lv['lineid']);$psls=$arr_psls['data'];
      //   $pslsnw=array();
      //   foreach($psls as $psv){

      //     //计算颜色和线边倒计时
      //     $arr_yuzhio=$yuzhi->getyuzhio($psv['psid'],$lv['lineid']);$yuzhio=$arr_yuzhio['data'];
      //     $xianbiantm=$psv['psleavetm'];
      //     if($xianbiantm<$yuzhio['yuzhired']){
      //       $psv['yuzhistat']='red';
      //     }else if($xianbiantm<$yuzhio['yuzhiyellow']){
      //       $psv['yuzhistat']='yellow';
      //     }else{
      //       $psv['yuzhistat']='green';
      //     }
      //     array_push($pslsnw,$psv);

      //   }
      //   $lv['psls']=$psls;

      //   array_push($linelsnw, $lv);
      // }
      // $this->assign('linels',$linelsnw);
      // 
      $psv_dflt= array(
          'psid' => 0,
          'f_ps_planid' => 0,
          'f_ps_lineid' => 0,
          'f_ps_itemid' => 0,
          'f_ps_partid' => 0,
          'psvolume' => 0,
          'psalready' => 0,
          'psremain' => 0,
          'psleavetm' => 0,
          'f_ps_psstatid' => 0,
          'psodr' => 0,
          'psclick' => 0,
          'lineid' => 0,
          'linenm' => 0,
          'linespeed' => 0,
          'lineip' => 0,
          'lineport' => 0,
          'linefull' => 0,
      );

      $pslsnw=array();$count=0;$max=60;
      foreach($linels as $lv){
        $arr_psls=$ps->getpslsbylineidandparttypels($lv['lineid'],$parttypels);$psls=$arr_psls['data'];

        if(count($psls)==0){
          $psv_dflt['psid']='lineid_'.$lv['lineid'];
          $psv_dflt['f_ps_lineid']=$lv['lineid'];
          $psv_dflt['lineid']=$lv['lineid'];
          $psv_dflt['linenm']=$lv['linenm'];
          $psv_dflt['linefull']=$lv['linefull'];
          array_push($pslsnw, $psv_dflt);
          $count++;
          continue;
        }
        
        foreach($psls as $psv){

          // $psv['partnm_c']=mb_substr($psv['partnm'],0,8,'utf-8').'...';
          $psv['partnm_c']=$psv['partcode'];
          $count++;

          //计算颜色和线边倒计时
          $arr_yuzhio=$yuzhi->getyuzhio($psv['f_ps_partid'],$lv['lineid']);$yuzhio=$arr_yuzhio['data'];
          $xianbiantm=$psv['psleavetm'];
          $psv['xianbiantm']=changeTimeType($xianbiantm*60);
          if($xianbiantm<$yuzhio['yuzhired']){
            $psv['yuzhistat']='danger';
          }else if($xianbiantm<$yuzhio['yuzhiyellow']){
            $psv['yuzhistat']='warning';
          }else{
            $psv['yuzhistat']='success';
          }

          // if($xianbiantm>$max){$max=$xianbiantm;}

          array_push($pslsnw,$psv);

        }
        
      }

      $this->assign('psls',$pslsnw);
      $this->assign('max',$max);
      $this->assign('count',$count);

      $tm=date('Y.m.d',time());
      $this->assign('tm',$tm);
      $this->assign('banner','配送');

      $this->display('query');
  
    }

    //公版
    public function gailan(){
      header("Content-Type:text/html; charset=utf-8");
      
      $environment=D('Environment');$plan=D('Plan');$ps=D('Ps');$banci=D('Banci');$fenzuparttype=D('Fenzuparttype');$line=D('Line');$yuzhi=D('Yuzhi');
      $arr_usross=$environment->setenvironment(MODULE_NAME);$usross=$arr_usross['data'];

      $this->assign('usross',$usross);
      $arr_bancio=$banci->getbanciobybanciid($usross['f_usr_banciid']);$bancio=$arr_bancio['data'];
      $this->assign('bancio',$bancio);
      $arr_parttypels=$fenzuparttype->getparttypelsbyfenzuid($usross['f_usr_fenzuid']);$parttypels=$arr_parttypels['data'];
      $str=$parttypels[0]['parttypenm'];
      if(count($parttypels)>1){
        foreach($parttypels as $ptv){
          $str=$str.'、'.$ptv['parttypenm'];
        }
      }
      $this->assign('parttypenmset',$str);


      $arr_linels=$line->getlinels();$linels=$arr_linels['data'];
      
      
      $psv_dflt= array(
          'psid' => 0,
          'f_ps_planid' => 0,
          'f_ps_lineid' => 0,
          'f_ps_itemid' => 0,
          'f_ps_partid' => 0,
          'psvolume' => 0,
          'psalready' => 0,
          'psremain' => 0,
          'psleavetm' => 0,
          'f_ps_psstatid' => 0,
          'psodr' => 0,
          'psclick' => 0,
          'lineid' => 0,
          'linenm' => 0,
          'linespeed' => 0,
          'lineip' => 0,
          'lineport' => 0,
          'linefull' => 0,
      );

      $pslsnw=array();$count=0;$max=0;
      foreach($linels as $lv){
        $arr_psls=$ps->getpslsbylineidandparttypels($lv['lineid'],$parttypels);$psls=$arr_psls['data'];

        // if(count($psls)==0){
        //   $psv_dflt['psid']='lineid_'.$lv['lineid'];
        //   $psv_dflt['f_ps_lineid']=$lv['lineid'];
        //   $psv_dflt['lineid']=$lv['lineid'];
        //   $psv_dflt['linenm']=$lv['linenm'];
        //   $psv_dflt['linefull']=$lv['linefull'];
        //   array_push($pslsnw, $psv_dflt);
        //   $count++;
        //   continue;
        // }
        
        foreach($psls as $psv){

          $psv['partnm_c']=mb_substr($psv['partnm'],0,8,'utf-8').'...';

          $count++;

          //计算颜色和线边倒计时
          $arr_yuzhio=$yuzhi->getyuzhio($psv['f_ps_partid'],$lv['lineid']);$yuzhio=$arr_yuzhio['data'];
          $xianbiantm=$psv['psleavetm'];
          $psv['xianbiantm']=changeTimeType($xianbiantm*60);
          if($xianbiantm<$yuzhio['yuzhired']){
            $psv['yuzhistat']='danger';
          }else if($xianbiantm<$yuzhio['yuzhiyellow']){
            $psv['yuzhistat']='warning';
          }else{
            $psv['yuzhistat']='success';
          }

          if($xianbiantm>$max){$max=$xianbiantm;}
          $psv['yuzhio']=$yuzhio;
          array_push($pslsnw,$psv);

        }
        
      }

      $this->assign('psls',$pslsnw);
      $this->assign('max',$max);
      $this->assign('count',$count);

      $tm=date('Y.m.d',time());
      $this->assign('tm',$tm);
      $this->assign('banner','配送');

      $this->display('gailan');
  
    }

    //公版
    public function yijianpeisong(){
      header("Content-Type:text/html; charset=utf-8");
      
      $environment=D('Environment');$plan=D('Plan');$ps=D('Ps');$banci=D('Banci');$fenzuparttype=D('Fenzuparttype');$line=D('Line');$yuzhi=D('Yuzhi');$para=D('Para');
      $arr_usross=$environment->setenvironment(MODULE_NAME);$usross=$arr_usross['data'];

      $this->assign('usross',$usross);
      $arr_bancio=$banci->getbanciobybanciid($usross['f_usr_banciid']);$bancio=$arr_bancio['data'];
      $this->assign('bancio',$bancio);
      $arr_parttypels=$fenzuparttype->getparttypelsbyfenzuid($usross['f_usr_fenzuid']);$parttypels=$arr_parttypels['data'];
      $str=$parttypels[0]['parttypenm'];
      if(count($parttypels)>1){
        foreach($parttypels as $ptv){
          $str=$str.'、'.$ptv['parttypenm'];
        }
      }
      $this->assign('parttypenmset',$str);

      $arr_parao=$para->getparao();$parao=$arr_parao['data'];

      $arr_linels=$line->getlinels();$linels=$arr_linels['data'];
      
      
      $psv_dflt= array(
          'psid' => 0,
          'f_ps_planid' => 0,
          'f_ps_lineid' => 0,
          'f_ps_itemid' => 0,
          'f_ps_partid' => 0,
          'psvolume' => 0,
          'psalready' => 0,
          'psremain' => 0,
          'psleavetm' => 0,
          'f_ps_psstatid' => 0,
          'psodr' => 0,
          'psclick' => 0,
          'lineid' => 0,
          'linenm' => 0,
          'linespeed' => 0,
          'lineip' => 0,
          'lineport' => 0,
          'linefull' => 0,
      );

      $pslsnw=array();$count=0;$max=0;

      $arr_psls=$ps->getpslsbypsleavetmASC($parao['paramaxpapertm'],$parttypels);$psls=$arr_psls['data'];

      

      // if(count($psls)==0){
      //   $psv_dflt['psid']='lineid_'.$lv['lineid'];
      //   $psv_dflt['f_ps_lineid']=$lv['lineid'];
      //   $psv_dflt['lineid']=$lv['lineid'];
      //   $psv_dflt['linenm']=$lv['linenm'];
      //   $psv_dflt['linefull']=$lv['linefull'];
      //   array_push($pslsnw, $psv_dflt);
      //   $count++;
      //   continue;
      // }
      
      foreach($psls as $psv){

        $psv['partnm_c']=mb_substr($psv['partnm'],0,8,'utf-8').'...';

        $count++;

        //计算颜色和线边倒计时
        $arr_yuzhio=$yuzhi->getyuzhio($psv['f_ps_partid'],$lv['lineid']);$yuzhio=$arr_yuzhio['data'];
        $xianbiantm=$psv['psleavetm'];
        $psv['xianbiantm']=changeTimeType($xianbiantm);
        if($xianbiantm<$yuzhio['yuzhired']){
          $psv['yuzhistat']='danger';
        }else if($xianbiantm<$yuzhio['yuzhiyellow']){
          $psv['yuzhistat']='warning';
        }else{
          $psv['yuzhistat']='success';
        }

        if($xianbiantm>$max){$max=$xianbiantm;}
        $psv['yuzhio']=$yuzhio;
        
        $psv['str']='已配送：'.$psv['psalready'].'；已生产：'.($psv['planrealvolume']).'箱；计划：'.$psv['planvolumebox'];

        //搞出百分比
        //第一段生产占比
        //第二段配送占比-生产占比
        //第三段剩下的占比
        
        $diyiduan=round($psv['planrealvolume']/$psv['planvolumebox'],2);
        $dierduan=round($psv['psalready']/$psv['psvolume']-$diyiduan,2);
        $disanduan=1-$diyiduan-$dierduan;
        $psv['diyiduan']=($diyiduan*100).'%';$psv['dierduan']=($dierduan*100).'%';$psv['disanduan']=($disanduan*100).'%';

        array_push($pslsnw,$psv);

      }
        
      

      $this->assign('psls',$pslsnw);
      $this->assign('max',$max);
      $this->assign('count',$count);

      $tm=date('Y.m.d',time());
      $this->assign('tm',$tm);
      $this->assign('banner','配送');

      $this->display('yijianpeisong');
  
    }

    //公版
    public function single_peisonging(){
      header("Content-Type:text/html; charset=utf-8");
      
      $environment=D('Environment');$plan=D('Plan');$ps=D('Ps');$banci=D('Banci');$fenzuparttype=D('Fenzuparttype');$line=D('Line');$yuzhi=D('Yuzhi');
      $arr_usross=$environment->setenvironment(MODULE_NAME);$usross=$arr_usross['data'];

      $this->assign('usross',$usross);
      $arr_bancio=$banci->getbanciobybanciid($usross['f_usr_banciid']);$bancio=$arr_bancio['data'];
      $this->assign('bancio',$bancio);
      $arr_parttypels=$fenzuparttype->getparttypelsbyfenzuid($usross['f_usr_fenzuid']);$parttypels=$arr_parttypels['data'];
      $str=$parttypels[0]['parttypenm'];
      if(count($parttypels)>1){
        foreach($parttypels as $ptv){
          $str=$str.'、'.$ptv['parttypenm'];
        }
      }
      $this->assign('parttypenmset',$str);

      $psid=$_GET['psid'];
      $arr_pso=$ps->getpsobypsid($psid);$pso=$arr_pso['data'];

      $ps->setpeisonging($psid);

      

      //计算颜色和线边倒计时
      $arr_yuzhio=$yuzhi->getyuzhio($pso['f_ps_partid'],$pso['f_ps_lineid']);$yuzhio=$arr_yuzhio['data'];$this->assign('yuzhio',$yuzhio);
      $xianbiantm=$pso['psleavetm'];
      $pso['xianbiantm']=changeTimeType($xianbiantm*60);
      if($xianbiantm<$yuzhio['yuzhired']){
        $pso['yuzhistat']='danger';
      }else if($xianbiantm<$yuzhio['yuzhiyellow']){
        $pso['yuzhistat']='warning';
      }else{
        $pso['yuzhistat']='success';
      }

      $this->assign('yuzhio',$yuzhio);
     
      $this->assign('pso',$pso);
      $tm=date('Y.m.d',time());
      $this->assign('tm',$tm);
      $this->assign('banner','配送');

      $this->display('single_peisonging');
  
    }

    

    //公版
    public function query_org(){
      header("Content-Type:text/html; charset=utf-8");
      $pb=D('PB');$para=D('Para');$line=D('Line');$plan=D('Plan');$part=D('Part');

      $arr_parao=$para->getparao();$parao=$arr_parao['data'];
      $this->assign('paramaxpapertm',$parao['paramaxpapertm']);

      $all=$this->all;

      if(gp()['quanbu']){
        $all['lmt_dflt']=10000000000;
      }else{
        if(gp()['lock']){
          $all['lmt_dflt']=gp()['lock'];
        }else{
          $arr_parao=$para->getparao();$parao=$arr_parao['data'];
          $all['lmt_dflt']=$parao['paramaxpapertm'];

        }
      }
      
      //全99999999的时候，必须把特殊条件体现出来
      $ps_m=M('ps');
      $psls=$ps_m->where('psodr<>99999999')->select();
      if(!$psls){
        $all['spccdtls']=array('spccdt_0'=>array('f_ps_psstatid<>1','把完成的搞掉'));
        $all['spccdt_dflt']=array('spccdt_0');
        $this->assign('lock',1);
      }


      $arr_mls=$pb->query($all);$mls=$arr_mls['data'];

      $mlsnw=array();
      foreach($mls as $mv){
        // //计算倒计时//暂时页面的倒计时没有想好怎么弄
        // $arr_lineo=$line->getlineobylineid($mv['f_ps_lineid']);$lineo=$arr_lineo['data'];
        // $seconds=$mv['psremain']/$lineo['linespeed']*60;
        // $psleavetm=changeTimeType($seconds);
        // $mv['psleavetm']=$psleavetm;
        $mv['psleavetm']=changeTimeType($mv['psleavetm']);
        $arr_plano=$plan->getplanobyplanid($mv['f_ps_planid']);$plano=$arr_plano['data'];
        $mv['plano']=$plano;
        $arr_parto=$part->getpartobypartid($mv['f_ps_partid']);$parto=$arr_parto['data'];
        $mv['parto']=$parto;
        array_push($mlsnw,$mv);
      }

      $this->assign('mls',$mlsnw);
      

      $tm=date('Y.m.d',time());
      $this->assign('tm',$tm);
      $this->assign('banner','配送');

      $this->display('query');
  
    }

    public function docheckpsstat(){ pd(222);
      header("Content-Type:text/html; charset=utf-8");
      $ps=D('Ps');

      $psid=gp()['psid'];
      
      $arr_pso=$ps->getpsobypsid($psid);$pso=$arr_pso['data'];
      if($pso['psalready']>=$pso['psvolume']){
        $ps->setpeisongcomplete($psid);
      }else{
        $ps->setpeisongzhunbei($psid);
      }

      
      $this->ajaxReturn($data,'json');
      
    }

    public function docheckpsstatandaddvolume(){
      header("Content-Type:text/html; charset=utf-8");
      $ps=D('Ps');

      $psid=gp()['psid'];$peisongliang=gp()['peisongliang'];

      $ps->addpeisongshuliang($psid,$peisongliang);
      
      $arr_pso=$ps->getpsobypsid($psid);$pso=$arr_pso['data'];
      if($pso['psalready']>=$pso['psvolume']){
        $ps->setpeisongcomplete($psid);
      }else{
        $ps->setpeisongzhunbei($psid);
      }

      
      $this->ajaxReturn($data,'json');
      
    }

    public function dopeisongliang(){
      header("Content-Type:text/html; charset=utf-8");
      $ps=D('Ps');

      $psid=gp()['psid'];
      $defaultpeisongliang=gp()['defaultpeisongliang'];

      $ps->addpeisongshuliang($psid,$defaultpeisongliang);

      
      $this->ajaxReturn($data,'json');
      
    }

    public function dojieshubeiliao(){
      header("Content-Type:text/html; charset=utf-8");
      $ps=D('Ps');

      $ps->jieshubeiliao();
      
      $this->ajaxReturn($data,'json');
      
    }

    public function dobeiliao(){
      header("Content-Type:text/html; charset=utf-8");
      $ps=D('Ps');

      $lmt=gp()['beiliaoshuliang'];

      $arr_truelmt=$ps->beiliao($lmt);$truelmt=$arr_truelmt['data'];
      
      $data['truelmt']=$truelmt;

      $this->ajaxReturn($data,'json');
      
    }

    
    
    //公版
    public function view(){
      header("Content-Type:text/html; charset=utf-8");
      $pb=D('PB');
      $pb->view($this->all);
      $this->display('Cmn:view');
    }
   
    //公版
    public function update(){
      header("Content-Type:text/html; charset=utf-8");
      $pb=D('PB');
      $pb->update($this->all);
      $this->display('Cmn:update');
    }

    //公版
    public function doupdate(){
      header("Content-Type:text/html; charset=utf-8");
      $pb=D('PB');
      $arr_pattern=$pb->doupdate($this->all);
      $data['pattern']=$arr_pattern['data'];

      $this->ajaxReturn($data,'json');
    }

    //公版
    public function dodelete(){
      header("Content-Type:text/html; charset=utf-8");
      $pb=D('PB');
      $pb->dodelete($this->all);
      
      $this->ajaxReturn($data,'json');
    }

    public function dolinkage(){
      header("Content-Type:text/html; charset=utf-8");
      $nb=D('NB');
      $arr=$nb->dolinkage($this->all);
      
      $data=$arr['data'];
      
      $this->ajaxReturn($data,'json');
    }

}